<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/1/24
 * Time: 0:36
 */

namespace app\api\controller;
use think\Request;

class Server extends  Common
{
    public function lists(){
        $page = input("page" , 1 , "intval");
        $pagesize = 20;
        $map = [] ;
        $data = model("Server")->lists("id,server,port",$map , $page , $pagesize);

        return output(0 , $data);
    }

    public function add(){
        $post = Request::instance()->post();
        //验证器
        $validate = validate("Server");
        if(!$validate->check($post)){
            return output(2000, ['msg' => $validate->getError()]);
        }
        $newid = model("Server")->add($post);
        if($newid){
            return output(0);
        }
        return output(1005);
    }

    public function remove(){
        $id = input("id" , 0 , "intval");

        if(!$id){
            return output(1004);
        }

        $row = model("Server")->remove($id);

        if($row !== false){
            return output(1005);
        }

        return output(0);
    }
}